package com.yang.designmode.singleton.business;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 日志类 单例模式 饿汉式
 */
public class Logger4 {
    //实现日志的输出
    private FileWriter fileWriter;

    private static Logger4 logger4 = new Logger4();

    //实现日志输出
    private Logger4() {
        File file = new File("./log.txt");
        try {
            FileWriter writer = new FileWriter(file, true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Logger4 getInstance() {
        return logger4;
    }

    /**
     * 对外输出日志的方法
     * @param message
     */
    public void log(String message) throws IOException {
            fileWriter.write(message);
    }
}
